define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable', 'echarts', 'echarts-theme'], function ($, undefined, Backend, Table, Form, undefined, Echarts, undefined) {

    var Controller = {
        index: function () {
            // 初始化表格參數配置
            Table.api.init({
                extend: {
                    index_url: 'aps/planlog/index',
                    add_url: 'aps/planlog/add',
                    edit_url: 'aps/planlog/edit',
                    del_url: 'aps/planlog/del',
                    multi_url: 'aps/planlog/multi',
                    table: 'aps_planlog',
                }
            });

            var table = $("#table");

            //給添加按鈕添加`data-area`屬性
            $(".btn-add").data("area", ["100%", "100%"]);
            //當內容渲染完成給編輯按鈕添加`data-area`屬性
            table.on('post-body.bs.table', function (e, settings, json, xhr) {
                $(".btn-editone").data("area", ["100%", "100%"]);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                showToggle: false,
                sortName: 'id',
                searchFormVisible: true,
                showToggle: false,
                showColumns: false,
                showExport: false,
                search: false,
                dblClickToEdit: false, //是否啟用雙擊編輯
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),  sortable: true},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'addtabs',
                                    title: __('詳情'),
                                    classname: 'btn btn-xs btn-warning btn-addtabs',
                                    icon: 'fa fa-dashboard',
                                    url: 'aps/planlog/detail'
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        },
                        {field: 'switch', title: __('排程開關'), searchList: {"1":__('Yes'),"0":__('No')}, formatter: Table.api.formatter.toggle},
                        {field: 'cxstate', title: __('產線'),  searchList: {"1":__('產線一'),"2":__('產線二')}, formatter: Table.api.formatter.normal},
                        {field: 'order.name', title: __('訂單名稱'), operate:false},
                        {field: 'workorder.name', title: __('Workorder.name'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符'},
                        {field: 'workorder.name', title: __('Workorder.name'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符'},
                        {field: 'workorder.MainProcessName', title: __('規格'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符', formatter: Controller.api.formatter.mainprocess},
                        {field: 'workorder.ProductNumber', title: __('產品品號'), operate:false},
                        {field: 'workorder.ProductName', title: __('產品品名'), operate:false},
                        {field: 'workorder.num', title: __('預計產量'), operate:false},
                        {
                            field: 'workorder_finishdate',
                            title: __('需求完工時間*'),
                            editable: {
                                emptytext: '--',
                                //disabled: !Config.caozuo , //true 則不能編輯 ---- 操作權限
                                success: function (response, newValue) {
                                    //window.location.reload();
                                }
                            },
                            operate:'RANGE',
                            addclass:'datetimerange',
                            sortable: true,
                        },


                        {field: 'pcyqzl', title: __('排程逾期製令'),  searchList: {"是":__('是'),"否":__('否')}, formatter: Table.api.formatter.normal, sortable: true},

                        {field: 'sjwg', title: __('Sjwg'), operate:false, addclass:'datetimerange', sortable: true},
                        {field: 'jhwg', title: __('Jhwg'), operate:false, addclass:'datetimerange', formatter: Controller.api.formatter.jhwg, sortable: true},
                        {field: 'state', title: __('State'), defaultValue:__('未完成'), searchList: {"未完成":__('未完成'),"已完成":__('已完成')}, formatter: Table.api.formatter.normal, sortable: true},

                        {field: 'finishnum', title: __('Finishnum'), operate:false},
                        {field: 'maxnum', title: __('Maxnum'), operate:false},


                        {field: 'yjkg', title: __('預計開工'), operate:false, addclass:'datetimerange', sortable: true},

                        //{field: 'procedure1_name', title: __('工序1'), operate:false},
                        //{field: 'procedure1_man_name', title: __('工序1操作工'), operate:false},
                        //{field: 'procedure1_preparedate', title: __('工序1原料備齊日*'), editable: true, operate:false},
                        //{field: 'procedure1_startdate', title: __('工序1開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        //{field: 'procedure1_finishdate', title: __('工序1完工日'), operate:false, formatter: Controller.api.formatter.datet},
                        //{field: 'procedure1_manhours', title: __('工序1工時'), operate:false},
                        //{field: 'procedure2_name', title: __('工序2'), operate:false},
                        //{field: 'procedure2_man_name', title: __('工序2操作工'), operate:false},
                        //{field: 'procedure2_preparedate', title: __('工序2原料備齊日*'), editable: true, operate:false},
                        //{field: 'procedure2_startdate', title: __('工序2開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        //{field: 'procedure2_finishdate', title: __('工序2完工日'), operate:false, formatter: Controller.api.formatter.datet},
                        //{field: 'procedure2_manhours', title: __('工序2工時'), operate:false},
                        //{field: 'procedure3_name', title: __('工序3'), operate:false},
                        //{field: 'procedure3_man_name', title: __('工序3操作工'), operate:false},
                        //{field: 'procedure3_preparedate', title: __('工序3原料備齊日*'), editable: true, operate:false},
                        //{field: 'procedure3_startdate', title: __('工序3開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        //{field: 'procedure3_finishdate', title: __('工序3完工日'), operate:false, formatter: Controller.api.formatter.datet},
                        //{field: 'procedure3_manhours', title: __('工序3工時'), operate:false},
                        //{field: 'procedure4_name', title: __('工序4'), operate:false},
                        //{field: 'procedure4_man_name', title: __('工序4操作工'), operate:false},
                        //{field: 'procedure4_preparedate', title: __('工序4原料備齊日*'), editable: true, operate:false},
                        //{field: 'procedure4_startdate', title: __('工序4開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        //{field: 'procedure4_finishdate', title: __('工序4完工日'), operate:false, formatter: Controller.api.formatter.datet},
                        //{field: 'procedure4_manhours', title: __('工序4工時'), operate:false},
                        //{field: 'procedure5_name', title: __('工序5'), operate:false},
                        //{field: 'procedure5_man_name', title: __('工序5操作工'), operate:false},
                        //{field: 'procedure5_preparedate', title: __('工序5原料備齊日*'), editable: true, operate:false},
                        //{field: 'procedure5_startdate', title: __('工序5開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        //{field: 'procedure5_finishdate', title: __('工序5完工日'), operate:false, formatter: Controller.api.formatter.datet},
                        //{field: 'procedure5_manhours', title: __('工序5工時'), operate:false},
                        //{field: 'procedure6_name', title: __('工序6'), operate:false},
                        //{field: 'procedure6_man_name', title: __('工序6操作工'), operate:false},
                        //{field: 'procedure6_preparedate', title: __('工序6原料備齊日*'), editable: true, operate:false},
                        //{field: 'procedure6_startdate', title: __('工序6開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        //{field: 'procedure6_finishdate', title: __('工序6完工日'), operate:false, formatter: Controller.api.formatter.datet},
                        //{field: 'procedure6_manhours', title: __('工序6工時'), operate:false},
                        //{field: 'procedure7_name', title: __('工序7'), operate:false},
                        //{field: 'procedure7_man_name', title: __('工序7操作工'), operate:false},
                        //{field: 'procedure7_preparedate', title: __('工序7原料備齊日*'), editable: true, operate:false},
                        //{field: 'procedure7_startdate', title: __('工序7開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        //{field: 'procedure7_finishdate', title: __('工序7完工日'), operate:false, formatter: Controller.api.formatter.datet},
                        //{field: 'procedure7_manhours', title: __('工序7工時'), operate:false},
                        //{field: 'procedure8_name', title: __('工序8'), operate:false},
                        //{field: 'procedure8_man_name', title: __('工序8操作工'), operate:false},
                        //{field: 'procedure8_preparedate', title: __('工序8原料備齊日*'), editable: true, operate:false},
                        //{field: 'procedure8_startdate', title: __('工序8開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        //{field: 'procedure8_finishdate', title: __('工序8完工日'), operate:false, formatter: Controller.api.formatter.datet},
                        //{field: 'procedure8_manhours', title: __('工序8工時'), operate:false},
                        //{field: 'procedure9_name', title: __('工序9'), operate:false},
                        //{field: 'procedure9_man_name', title: __('工序9操作工'), operate:false},
                        //{field: 'procedure9_preparedate', title: __('工序9原料備齊日*'), editable: true, operate:false},
                        //{field: 'procedure9_startdate', title: __('工序9開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        //{field: 'procedure9_finishdate', title: __('工序9完工日'), operate:false, formatter: Controller.api.formatter.datet},
                        //{field: 'procedure9_manhours', title: __('工序9工時'), operate:false},
                        //{field: 'procedure10_name', title: __('工序10'), operate:false},
                        //{field: 'procedure10_man_name', title: __('工序10操作工'), operate:false},
                        //{field: 'procedure10_preparedate', title: __('工序10原料備齊日*'), editable: true, operate:false},
                        //{field: 'procedure10_startdate', title: __('工序10開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        //{field: 'procedure10_finishdate', title: __('工序10完工日'), operate:false, formatter: Controller.api.formatter.datet},
                        //{field: 'procedure10_manhours', title: __('工序10工時'), operate:false},
                        //{field: 'procedure11_name', title: __('工序11'), operate:false},
                        //{field: 'procedure11_man_name', title: __('工序11操作工'), operate:false},
                        //{field: 'procedure11_preparedate', title: __('工序11原料備齊日*'), editable: true, operate:false},
                        //{field: 'procedure11_startdate', title: __('工序11開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        //{field: 'procedure11_finishdate', title: __('工序11完工日'), operate:false, formatter: Controller.api.formatter.datet},
                        //{field: 'procedure11_manhours', title: __('工序11工時'), operate:false},
                        //{field: 'procedure12_name', title: __('工序12'), operate:false},
                        //{field: 'procedure12_man_name', title: __('工序12操作工'), operate:false},
                        //{field: 'procedure12_preparedate', title: __('工序12原料備齊日*'), editable: true, operate:false},
                        //{field: 'procedure12_startdate', title: __('工序12開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        //{field: 'procedure12_finishdate', title: __('工序12完工日'), operate:false, formatter: Controller.api.formatter.datet},
                        //{field: 'procedure12_manhours', title: __('工序12工時'), operate:false},

                        {field: 'overtime_hours', title: __('需加班工時'), operate:false},

                        //{field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime, operate:false},

                    ]
                ]
            });

            //點擊智能排單
            $(document).on("click", ".znpd", function () {
                var url = 'aps/planlog/znpd';
                var options = {
                    shadeClose: false,
                    shade: [0.3, '#393D49'],
                    area: ["100%", "100%"],
                    callback:function(data){
                        window.location.reload();
                    }
                };
                Fast.api.open(url, "智能排單結果", options);
            });

            $(document).on("click", ".btn-selected3", function () {
                var ids = Table.api.selectedids(table);
                console.log(ids);
                var url = 'aps/planlog/gantt_z?ids=' + ids;
                var options = {
                    shadeClose: false,
                    shade: [0.3, '#393D49'],
                    area: ["100%", "100%"],
                    callback:function(data){
                        window.location.reload();
                    }
                };
                Fast.api.open(url, "工序甘特圖", options);
            });

            $(document).on("click", ".pcak", function () {
                var url = 'aps/planlog/pcak';
                var _this = $(this);
                Fast.api.ajax({
                    url: url,
                }, function (data, ret) {
                    if (ret.data.switch == 0) {
                        _this.html('排程全開');
                    } else {
                        _this.html('排程全關');
                    }
                    $(".btn-refresh").trigger("click");
                });
            });

            $(document).on('click', '.pdday', function () {
                var url = 'aps/planlog/editpdday';

                var options = {
                    shadeClose: false,
                    shade: [0.3, '#393D49'],
                    area: ["80%", "80%"],
                    callback:function(data){
                        $("#c_note").text(data);
                    }
                };
                Fast.api.open(url, "排單開始日", options);
            });

            $(document).on("dblclick", ".mainprocess", function () {
                var url = $(this).data('id');
                var options = {
                    shadeClose: false,
                    shade: [0.3, '#393D49'],
                    area: ["80%", "80%"],
                    callback:function(data){

                    }
                };
                Fast.api.open(url, "主制程列表", options);
            });

            // 為表格綁定事件
            Table.api.bindevent(table);
        },
        editpdday: function () {
            Controller.api.bindevent();
            $(document).on('click', '.khbz', function () {
                var data = $("#c-pdday").val();
                //確實從這裏傳入
                Fast.api.close("排單開始日: " + data);
            });
        },
        xckb: function () {
            setInterval(function () {
                window.location.reload();
            }, 60000);//1分鐘刷新一次

        },
        xckb2: function () {
            setInterval(function () {
                window.location.reload();
            }, 60000);//1分鐘刷新一次

        },
        index1: function () {
            // 初始化表格參數配置
            Table.api.init({
                extend: {
                    index_url: 'aps/planlog/index1',
                    add_url: '',
                    edit_url: 'aps/planlog/edit',
                    del_url: '',
                    multi_url: '',
                    table: 'aps_planlog',
                }
            });

            var table = $("#table");

            //給添加按鈕添加`data-area`屬性
            $(".btn-add").data("area", ["100%", "100%"]);
            //當內容渲染完成給編輯按鈕添加`data-area`屬性
            table.on('post-body.bs.table', function (e, settings, json, xhr) {
                $(".btn-editone").data("area", ["100%", "100%"]);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                showToggle: false,
                sortName: 'id',
                searchFormVisible: true,
                showToggle: false,
                showColumns: false,
                showExport: false,
                search: false,
                dblClickToEdit: false, //是否啟用雙擊編輯
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: function (value, row, index) {
                                var table = this.table;
                                // 操作配置
                                var options = table ? table.bootstrapTable('getOptions') : {};
                                // 默認按鈕組
                                var buttons = $.extend([], this.buttons || []);
                                // 所有按鈕名稱
                                var names = [];
                                buttons.forEach(function (item) {
                                    names.push(item.name);
                                });
                                if (options.extend.dragsort_url !== '' && names.indexOf('dragsort') === -1) {
                                    buttons.push({
                                        name: 'dragsort',
                                        icon: 'fa fa-arrows',
                                        title: __('Drag to sort'),
                                        extend: 'data-toggle="tooltip"',
                                        classname: 'btn btn-xs btn-primary btn-dragsort'
                                    });
                                }
                                if (options.extend.edit_url !== '' && names.indexOf('edit') === -1) {
                                    buttons.push({
                                        name: 'edit',
                                        icon: 'fa fa-gavel',
                                        title: __('打卡'),
                                        extend: 'data-toggle="tooltip"',
                                        classname: 'btn btn-xs btn-success btn-editone',
                                        url: options.extend.edit_url
                                    });
                                }

                                if (options.extend.del_url !== '' && names.indexOf('del') === -1) {
                                    buttons.push({
                                        name: 'del',
                                        icon: 'fa fa-trash',
                                        title: __('Del'),
                                        extend: 'data-toggle="tooltip"',
                                        classname: 'btn btn-xs btn-danger btn-delone'
                                    });
                                }
                                return Table.api.buttonlink(this, buttons, value, row, index, 'operate');
                            }
                        },
                        {field: 'workorder.name', title: __('Workorder.name')},
                        {field: 'workorder.mtype', title: __('產品分類'), operate:false},
                        {field: 'workorder_finishdate', title: __('需求完工時間'), operate:false},
                        {field: 'sjwg', title: __('Sjwg'), operate:false, sortable: true},
                        {field: 'jhwg', title: __('Jhwg'), operate:'RANGE', addclass:'datetimerange', formatter: Controller.api.formatter.jhwg, sortable: true},

                        {field: 'finishnum', title: __('Finishnum'), operate:false},
                        {field: 'maxnum', title: __('Maxnum'), operate:false},
                        {field: 'procedure1_name', title: __('工序1'), operate:false},
                        {field: 'procedure1_man_name', title: __('工序1操作工'), operate:false},
                        {field: 'procedure1_preparedate', title: __('工序1原料備齊日*'), operate:false},
                        {field: 'procedure1_startdate', title: __('工序1開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        {field: 'procedure1_finishdate', title: __('工序1完工日'), operate:false, formatter: Controller.api.formatter.pr1},
                        {field: 'procedure1_manhours', title: __('工序1工時'), operate:false},
                        {field: 'procedure2_name', title: __('工序2'), operate:false},
                        {field: 'procedure2_man_name', title: __('工序2操作工'), operate:false},
                        {field: 'procedure2_preparedate', title: __('工序2原料備齊日*'), operate:false},
                        {field: 'procedure2_startdate', title: __('工序2開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        {field: 'procedure2_finishdate', title: __('工序2完工日'), operate:false, formatter: Controller.api.formatter.pr2},
                        {field: 'procedure2_manhours', title: __('工序2工時'), operate:false},
                        {field: 'procedure3_name', title: __('工序3'), operate:false},
                        {field: 'procedure3_man_name', title: __('工序3操作工'), operate:false},
                        {field: 'procedure3_preparedate', title: __('工序3原料備齊日*'), operate:false},
                        {field: 'procedure3_startdate', title: __('工序3開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        {field: 'procedure3_finishdate', title: __('工序3完工日'), operate:false, formatter: Controller.api.formatter.pr3},
                        {field: 'procedure3_manhours', title: __('工序3工時'), operate:false},
                        {field: 'procedure4_name', title: __('工序4'), operate:false},
                        {field: 'procedure4_man_name', title: __('工序4操作工'), operate:false},
                        {field: 'procedure4_preparedate', title: __('工序4原料備齊日*'), operate:false},
                        {field: 'procedure4_startdate', title: __('工序4開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        {field: 'procedure4_finishdate', title: __('工序4完工日'), operate:false, formatter: Controller.api.formatter.pr4},
                        {field: 'procedure4_manhours', title: __('工序4工時'), operate:false},
                        {field: 'procedure5_name', title: __('工序5'), operate:false},
                        {field: 'procedure5_man_name', title: __('工序5操作工'), operate:false},
                        {field: 'procedure5_preparedate', title: __('工序5原料備齊日*'), operate:false},
                        {field: 'procedure5_startdate', title: __('工序5開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        {field: 'procedure5_finishdate', title: __('工序5完工日'), operate:false, formatter: Controller.api.formatter.pr5},
                        {field: 'procedure5_manhours', title: __('工序5工時'), operate:false},
                        {field: 'procedure6_name', title: __('工序6'), operate:false},
                        {field: 'procedure6_man_name', title: __('工序6操作工'), operate:false},
                        {field: 'procedure6_preparedate', title: __('工序6原料備齊日*'), operate:false},
                        {field: 'procedure6_startdate', title: __('工序6開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        {field: 'procedure6_finishdate', title: __('工序6完工日'), operate:false, formatter: Controller.api.formatter.pr6},
                        {field: 'procedure6_manhours', title: __('工序6工時'), operate:false},
                        {field: 'procedure7_name', title: __('工序7'), operate:false},
                        {field: 'procedure7_man_name', title: __('工序7操作工'), operate:false},
                        {field: 'procedure7_preparedate', title: __('工序7原料備齊日*'), operate:false},
                        {field: 'procedure7_startdate', title: __('工序7開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        {field: 'procedure7_finishdate', title: __('工序7完工日'), operate:false, formatter: Controller.api.formatter.pr7},
                        {field: 'procedure7_manhours', title: __('工序7工時'), operate:false},
                        {field: 'procedure8_name', title: __('工序8'), operate:false},
                        {field: 'procedure8_man_name', title: __('工序8操作工'), operate:false},
                        {field: 'procedure8_preparedate', title: __('工序8原料備齊日*'), operate:false},
                        {field: 'procedure8_startdate', title: __('工序8開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        {field: 'procedure8_finishdate', title: __('工序8完工日'), operate:false, formatter: Controller.api.formatter.pr8},
                        {field: 'procedure8_manhours', title: __('工序8工時'), operate:false},
                        {field: 'procedure9_name', title: __('工序9'), operate:false},
                        {field: 'procedure9_man_name', title: __('工序9操作工'), operate:false},
                        {field: 'procedure9_preparedate', title: __('工序9原料備齊日*'), operate:false},
                        {field: 'procedure9_startdate', title: __('工序9開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        {field: 'procedure9_finishdate', title: __('工序9完工日'), operate:false, formatter: Controller.api.formatter.pr9},
                        {field: 'procedure9_manhours', title: __('工序9工時'), operate:false},
                        {field: 'procedure10_name', title: __('工序10'), operate:false},
                        {field: 'procedure10_man_name', title: __('工序10操作工'), operate:false},
                        {field: 'procedure10_preparedate', title: __('工序10原料備齊日*'), operate:false},
                        {field: 'procedure10_startdate', title: __('工序10開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        {field: 'procedure10_finishdate', title: __('工序10完工日'), operate:false, formatter: Controller.api.formatter.pr10},
                        {field: 'procedure10_manhours', title: __('工序10工時'), operate:false},
                        {field: 'procedure11_name', title: __('工序11'), operate:false},
                        {field: 'procedure11_man_name', title: __('工序11操作工'), operate:false},
                        {field: 'procedure11_preparedate', title: __('工序11原料備齊日*'), operate:false},
                        {field: 'procedure11_startdate', title: __('工序11開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        {field: 'procedure11_finishdate', title: __('工序11完工日'), operate:false, formatter: Controller.api.formatter.pr11},
                        {field: 'procedure11_manhours', title: __('工序11工時'), operate:false},
                        {field: 'procedure12_name', title: __('工序12'), operate:false},
                        {field: 'procedure12_man_name', title: __('工序12操作工'), operate:false},
                        {field: 'procedure12_preparedate', title: __('工序12原料備齊日*'), operate:false},
                        {field: 'procedure12_startdate', title: __('工序12開工日'), operate:false, formatter: Controller.api.formatter.datet, sortable: true},
                        {field: 'procedure12_finishdate', title: __('工序12完工日'), operate:false, formatter: Controller.api.formatter.pr12},
                        {field: 'procedure12_manhours', title: __('工序12工時'), operate:false},
                        //{field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime, operate:false},

                    ]
                ]
            });

            //點擊智能排單
            $(document).on("click", ".znpd", function () {
                var url = 'aps/planlog/znpd';
                var options = {
                    shadeClose: false,
                    shade: [0.3, '#393D49'],
                    area: ["100%", "100%"],
                    callback:function(data){
                        window.location.reload();
                    }
                };
                Fast.api.open(url, "智能排單結果", options);
            });

            // 批量重置
            $(document).on("click", ".btn-selected", function () {
                var ids = Table.api.selectedids(table);
                var url = 'aps/planlog/plcz?ids=' + ids;

                var that = this;
                Layer.confirm(__('確定執行批量重置?'), {icon: 3, title: '提示'}, function (index) {
                    Backend.api.ajax({
                        url: url,
                        //data: {name: $(that).data("name")}
                    }, function () {
                        Layer.close(index);
                        window.location.reload();
                    });
                });
            });

            $(document).on("click", ".btn-selected3", function () {
                var ids = Table.api.selectedids(table);
                console.log(ids);
                var url = 'aps/planlog/gantt_z?ids=' + ids;
                var options = {
                    shadeClose: false,
                    shade: [0.3, '#393D49'],
                    area: ["100%", "100%"],
                    callback:function(data){
                        window.location.reload();
                    }
                };
                Fast.api.open(url, "工序甘特圖", options);
            });

            // 為表格綁定事件
            Table.api.bindevent(table);
        },
        index2: function () {
            // 初始化表格參數配置
            Table.api.init({
                extend: {
                    index_url: 'aps/planlog/index2',
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: '',
                    table: 'aps_planlog',
                }
            });

            var table = $("#table");

            //當表格數據加載完成時
            table.on('load-success.bs.table', function (e, data) {
                $("#c_jrgs").text("今日總工時：" + data.extend.jrgs + " 小時 （" + data.extend.mannum + "人）");
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                showToggle: false,
                sortName: 'id',
                searchFormVisible: true,
                showColumns: false,
                search: false,
                dblClickToEdit: false, //是否啟用雙擊編輯
                showExport: false,
                //smartDisplay: false,
                //pageSize: 'All',
                //pageList: ['All'],
                columns: [
                    [
                        {field: 'today', title: __('日期'), visible:false, defaultValue: Controller.api.defaultdate(), addclass:'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'},
                        {field: 'cxstate', title: __('產線'),  searchList: {"1":__('產線一'),"2":__('產線二')}, formatter: Table.api.formatter.normal},
                        {field: 'procedure_name', title: __('工序'), operate: false},
                        {field: 'man_name', title: __('開工人員'), operate: false},
                        {field: 'man_num', title: __('開工人數'), operate: false},
                        {field: 'num', title: __('產量'), operate: false},
                        {field: 'startdate', title: __('開工時間'), operate: false},
                        {field: 'manhours', title: __('預估工時'), operate: false},
                        {field: 'zt', title: __('工作狀態'), operate: false},
                        {
                            field: 'workorder_name',
                            title: __('工單'),
                            operate: false,
                            formatter: function (value, row, index) {
                                //http://ants.megowx.com/admin/aps/planlog/detail?ids=1968
                                return [
                                    '<a href="/admin/aps/planlog/detail?ids=' + row.planlog_id + '&ref=addtabs" target="_parent" >' + value + '</a>'
                                ].join("")
                                //return [
                                //    '<a href="/admin/aps/planlog/detail?ids=' + row.planlog_id + '"  >' + value + '</a>'
                                //].join("")
                            }
                        },
                        {field: 'MainProcessName', title: __('規格'), operate: false},
                        {field: 'ProductNumber', title: __('品號'), operate: false},
                    ]
                ]
            });

            $(document).on("click", ".workorder", function () {

                return false;
            });

            // 為表格綁定事件
            Table.api.bindevent(table);
        },
        znpd: function () {

            Controller.api.bindevent();

            Table.api.init({
                extend: {
                    index_url: 'aps/planlog/znpdlist',
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: '',
                    table: 'aps_planlog',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                search:false,
                showToggle: false,
                showColumns: false,
                commonSearch: false,
                showExport: false,
                dblClickToEdit: false, //是否啟用雙擊編輯
                searchFormVisible: true,
                columns: [
                    [
                        {field: 'name', title: __('Workorder.name')},
                        {field: 'workorder_finishdate_new', title: __('新-計劃完工時間'), operate:false},
                        {field: 'workorder_finishdate', title: __('舊-計劃完工時間'), operate:false},
                    ]
                ]
            });

            // 為表格綁定事件
            Table.api.bindevent(table);

        },
        gstj0: function () {

            var myChart = Echarts.init(document.getElementById('echart'), 'walden');

            var posList = [
                'left', 'right', 'top', 'bottom',
                'inside',
                'insideTop', 'insideLeft', 'insideRight', 'insideBottom',
                'insideTopLeft', 'insideTopRight', 'insideBottomLeft', 'insideBottomRight'
            ];

            var app = [];
            app.configParameters = {
                rotate: {
                    min: -90,
                    max: 90
                },
                align: {
                    options: {
                        left: 'left',
                        center: 'center',
                        right: 'right'
                    }
                },
                verticalAlign: {
                    options: {
                        top: 'top',
                        middle: 'middle',
                        bottom: 'bottom'
                    }
                },
                position: {
                    options: Echarts.util.reduce(posList, function (map, pos) {
                        map[pos] = pos;
                        return map;
                    }, {})
                },
                distance: {
                    min: 0,
                    max: 100
                }
            };

            app.config = {
                rotate: 90,
                align: 'left',
                verticalAlign: 'middle',
                position: 'insideBottom',
                distance: 10,
                onChange: function () {
                    var labelOption = {
                        normal: {
                            rotate: app.config.rotate,
                            align: app.config.align,
                            verticalAlign: app.config.verticalAlign,
                            position: app.config.position,
                            distance: app.config.distance
                        }
                    };
                    myChart.setOption({
                        series: [{
                            label: labelOption
                        }, {
                            label: labelOption
                        }, {
                            label: labelOption
                        }, {
                            label: labelOption
                        }]
                    });
                }
            };

            var labelOption = {
                normal: {
                    show: true,
                    position: app.config.position,
                    distance: app.config.distance,
                    align: app.config.align,
                    verticalAlign: app.config.verticalAlign,
                    rotate: app.config.rotate,
                    formatter: '{c}  {name|{a}}',
                    fontSize: 8,
                    rich: {
                        name: {
                            textBorderColor: '#fff'
                        }
                    }
                }
            };

            var xlist = [];
            var y1list = [];
            var y2list = [];
            var y3list = [];
            for (var i = 0; i < Statsdata.list.length; i++) {
                //xlist.push(Statsdata.list[i].mainprocessname + '\n' + Statsdata.list[i].procedurename);
                xlist.push(Statsdata.list[i].procedurename);
                y1list.push(Math.ceil(Statsdata.list[i].MaxManhours * 60));
                y2list.push(Math.ceil(Statsdata.list[i].AVGManhours * 60));
                y3list.push(Math.ceil(Statsdata.list[i].MinManhours * 60));
            }

            option = {
                title: {
                    text: "",
                    subtext: ' 單位:分鐘',
                    left: 'left'
                },
                //color: ['#003366', '#006699', '#4cabce', '#e5323e'],
                color: ['#003366', '#006699', '#4cabce'],
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    }
                },
                legend: {
                    //data: ['Forest', 'Steppe', 'Desert', 'Wetland']
                    data: ['最大', '平均', '最小']
                },
                toolbox: {
                    show: true,
                    orient: 'vertical',
                    left: 'right',
                    top: 'center',
                    feature: {
                        mark: {show: true},
                        dataView: {show: true, readOnly: false},
                        magicType: {show: true, type: ['line', 'bar', 'stack', 'tiled']},
                        restore: {show: true},
                        saveAsImage: {show: true}
                    }
                },
                calculable: true,
                xAxis: [
                    {
                        type: 'category',
                        axisTick: {show: false},
                        data: xlist,
                        axisLabel: {
                            interval: 0,//橫軸信息全部顯示
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value'
                    }
                ],
                series: [
                    {
                        name: '最大',
                        type: 'bar',
                        barGap: 0,
                        label: labelOption,
                        //data: [320, 332, 301, 334, 390]
                        data: y1list
                    },
                    {
                        name: '平均',
                        type: 'bar',
                        label: labelOption,
                        //data: [220, 182, 191, 234, 290]
                        data: y2list
                    },
                    {
                        name: '最小',
                        type: 'bar',
                        label: labelOption,
                        //data: [150, 232, 201, 154, 190]
                        data: y3list
                    }
                ],
                dataZoom : [
                    {
                        type: 'slider',
                        show: true,
                        start: 0,
                        end: 1,
                        handleSize: 8
                    },
                    {
                        type: 'inside',
                        start: 0,
                        end: 1
                    },
                    {
                        type: 'slider',
                        show: true,
                        yAxisIndex: 0,
                        filterMode: 'empty',
                        width: 12,
                        height: '70%',
                        handleSize: 8,
                        showDataShadow: false,
                        left: '99%'
                    }
                ]
            };

            myChart.setOption(option);

        },
        gstj: function () {

            var myChart = Echarts.init(document.getElementById('echart'), 'walden');

            var posList = [
                'left', 'right', 'top', 'bottom',
                'inside',
                'insideTop', 'insideLeft', 'insideRight', 'insideBottom',
                'insideTopLeft', 'insideTopRight', 'insideBottomLeft', 'insideBottomRight'
            ];

            var app = [];
            app.configParameters = {
                rotate: {
                    min: -90,
                    max: 90
                },
                align: {
                    options: {
                        left: 'left',
                        center: 'center',
                        right: 'right'
                    }
                },
                verticalAlign: {
                    options: {
                        top: 'top',
                        middle: 'middle',
                        bottom: 'bottom'
                    }
                },
                position: {
                    options: Echarts.util.reduce(posList, function (map, pos) {
                        map[pos] = pos;
                        return map;
                    }, {})
                },
                distance: {
                    min: 0,
                    max: 100
                }
            };

            app.config = {
                rotate: 90,
                align: 'left',
                verticalAlign: 'middle',
                position: 'insideBottom',
                distance: 10,
                onChange: function () {
                    var labelOption = {
                        normal: {
                            rotate: app.config.rotate,
                            align: app.config.align,
                            verticalAlign: app.config.verticalAlign,
                            position: app.config.position,
                            distance: app.config.distance
                        }
                    };
                    myChart.setOption({
                        series: [{
                            label: labelOption
                        }, {
                            label: labelOption
                        }, {
                            label: labelOption
                        }, {
                            label: labelOption
                        }]
                    });
                }
            };

            var labelOption = {
                normal: {
                    show: true,
                    position: app.config.position,
                    distance: app.config.distance,
                    align: app.config.align,
                    verticalAlign: app.config.verticalAlign,
                    rotate: app.config.rotate,
                    formatter: '{c}  {name|{a}}',
                    fontSize: 12,
                    rich: {
                        name: {
                            textBorderColor: '#fff'
                        }
                    }
                }
            };

            var xlist = [];
            var y1list = [];
            var y2list = [];
            for (var i = 0; i < Statsdata.list.length; i++) {
                xlist.push(Statsdata.list[i].procedurename);
                y1list.push(Math.ceil(Statsdata.list[i].AVGManhours * 60));
                y2list.push(Math.ceil(Statsdata.list[i].manhours * 60));
            }

            option = {
                title: {
                    text: "工單：" + Statsdata.workordername,
                    subtext: ' 單位:分鐘',
                    left: 'left'
                },
                //color: ['#003366', '#006699', '#4cabce', '#e5323e'],
                color: ['#003366', '#006699'],
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    }
                },
                legend: {
                    //data: ['Forest', 'Steppe', 'Desert', 'Wetland']
                    data: ['平均', '此工單']
                },
                toolbox: {
                    show: true,
                    orient: 'vertical',
                    left: 'right',
                    top: 'center',
                    feature: {
                        mark: {show: true},
                        dataView: {show: true, readOnly: false},
                        magicType: {show: true, type: ['line', 'bar', 'stack', 'tiled']},
                        restore: {show: true},
                        saveAsImage: {show: true}
                    }
                },
                calculable: true,
                xAxis: [
                    {
                        type: 'category',
                        axisTick: {show: false},
                        data: xlist,
                        axisLabel: {
                            interval: 0,//橫軸信息全部顯示
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value'
                    }
                ],
                series: [
                    {
                        name: '平均',
                        type: 'bar',
                        label: labelOption,
                        data: y1list
                    },
                    {
                        name: '此工單',
                        type: 'bar',
                        label: labelOption,
                        data: y2list
                    }
                ]
            };

            myChart.setOption(option);

        },
        gantt_z: function () {

            Date.prototype.Format = function (fmt) {
                var o = {
                    "M+": this.getMonth() + 1, //月份
                    "d+": this.getDate(), //日
                    "H+": this.getHours(), //小時
                    "m+": this.getMinutes(), //分
                    "s+": this.getSeconds(), //秒
                    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                    "S": this.getMilliseconds() //毫秒
                };
                if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                for (var k in o)
                    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                return fmt;
            };

            var myChart = Echarts.init(document.getElementById('echart'), 'walden');
            var data = [];
            var wolist = Statsdata.wolist;//工單

            Echarts.util.each(wolist, function (wo, index) {

                var row = Statsdata.rawData[index];
                console.log(row.procedure_mans);

                for (var i = 0; i < row.maxnum; i++) {
                    var manname = row.procedure_mans[i];
                    var color = '#999ce1';
                    switch (row.procedure_manids[i]) {
                        default:
                            break;
                        case 0:
                            color = '#7b9ce1';
                            break;
                        case 1:
                            color = '#bd6d6c';
                            break;
                        case 2:
                            color = '#75d874';
                            break;
                        case 3:
                            color = '#7b9c00';
                            break;
                        case 4:
                            color = '#bd6dff';
                            break;
                        case 5:
                            color = '#ffd874';
                            break;
                        case 6:
                            color = '#7bffe1';
                            break;
                        case 7:
                            color = '#bffd6c';
                            break;
                        case 8:
                            color = '#75d004';
                            break;
                        case 9:
                            color = '#700ce1';
                            break;
                        case 10:
                            color = '#b00d6c';
                            break;
                        case 11:
                            color = '#ffd874';
                            break;
                        case 12:
                            color = '#b00d6c';
                            break;
                        case 13:
                            color = '#f00874';
                            break;
                        case 14:
                            color = '#ffd004';
                            break;

                    }
                    data.push({
                        name: row.procedure_names[i] + " [" + manname + "]",
                        value: [
                            index,
                            row.start_times[i] + 200,
                            row.end_times[i],
                            new Date(row.start_times[i] * 1000).Format("MM-dd HH:mm") + "~" + new Date(row.end_times[i] * 1000).Format("MM-dd HH:mm")
                        ],
                        itemStyle: {
                            normal: {
                                color: color
                            }
                        }
                    });
                }

            });

            function renderItem(params, api) {
                var categoryIndex = api.value(0);
                var start = api.coord([api.value(1), categoryIndex]);
                var end = api.coord([api.value(2), categoryIndex]);
                var height = api.size([0, 1])[1] * 0.6;

                var rectShape = Echarts.graphic.clipRectByRect({
                    x: start[0],
                    y: start[1] - height / 2,
                    width: end[0] - start[0],
                    height: height
                }, {
                    x: params.coordSys.x,
                    y: params.coordSys.y,
                    width: params.coordSys.width,
                    height: params.coordSys.height
                });

                return rectShape && {
                        type: 'rect',
                        shape: rectShape,
                        style: api.style()
                    };
            }

            option = {
                tooltip: {
                    formatter: function (params) {
                        return params.marker + params.name + ': ' + params.value[3];
                    }
                },
                title: {
                    text: '工序甘特圖',
                    left: 'center'
                },
                dataZoom: [{
                    type: 'slider',
                    filterMode: 'weakFilter',
                    showDataShadow: false,
                    top: Statsdata.zoomtop,
                    height: 10,
                    borderColor: 'transparent',
                    backgroundColor: '#e2e2e2',
                    handleIcon: 'M10.7,11.9H9.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7v-1.2h6.6z M13.3,22H6.7v-1.2h6.6z M13.3,19.6H6.7v-1.2h6.6z', // jshint ignore:line
                    handleSize: 20,
                    handleStyle: {
                        shadowBlur: 6,
                        shadowOffsetX: 1,
                        shadowOffsetY: 2,
                        shadowColor: '#aaa'
                    },
                    labelFormatter: ''
                }, {
                    type: 'inside',
                    filterMode: 'weakFilter'
                }],
                grid: {
                    height:Statsdata.gridh
                },
                xAxis: {
                    min: Statsdata.baseTime,
                    scale: true,
                    axisLabel: {
                        formatter: function (val) {
                            return new Date(val * 1000).Format("MM-dd");
                        }
                    }
                },
                yAxis: {
                    data: wolist
                },
                series: [{
                    type: 'custom',
                    renderItem: renderItem,
                    itemStyle: {
                        normal: {
                            opacity: 0.8
                        }
                    },
                    encode: {
                        x: [1, 2],
                        y: 0
                    },
                    data: data
                }]
            };

            myChart.setOption(option);

        },
        tzrl: function () {
            Table.api.init({
                extend: {
                    index_url: 'aps/planlog/tzrl',
                    add_url: '',
                    edit_url: 'aps/planlog/edit',
                    del_url: '',
                    multi_url: '',
                    table: 'aps_planlog',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showColumns: false,
                commonSearch: false,
                showExport: false,
                columns: [
                    [
                        //{field: 'id', title: __('順序'), operate:false},
                        {field: 'workorder.name', title: __('工單名稱'), operate: false},
                        {field: 'workorder.MainProcessName', title: __('規格'), operate: false},
                        {field: 'procedure_name', title: __('工序名稱'), operate:false},
                        {field: 'manhours', title: __('原工時'), operate:false},
                        {field: 'manhours2', title: __('調整後工時'), operate:false, formatter: Controller.api.formatter.manhours2},
                        {field: 'man_num', title: __('目前人力'), operate:false},
                        {
                            field: 'man_num2',
                            title: __('調整人力'),
                            editable: {
                                emptytext: '無',
                                rows:10,
                                tpl: "<textarea rows='10' cols='50'></textarea>",
                                success: function (response, newValue) {
                                    //$(".btn-refresh").trigger("click");
                                }
                            },
                            operate: false,
                            align: 'left',
                        },
                    ]
                ]
            });

            // 為表格綁定事件
            Table.api.bindevent(table);
        },
        ygyg: function () {

            var myChart = Echarts.init(document.getElementById('echart'), 'walden');

            option = {
                tooltip : {
                    trigger: 'axis',
                    axisPointer : {            // 坐標軸指示器，坐標軸觸發有效
                        type : 'shadow'        // 默認為直線，可選為：'line' | 'shadow'
                    },
                },
                title: {
                    text: '每日用工預估',
                    subtext: '投入人力:' + Statsdata.mannum + '人', //小灰字
                    left: 'center'
                },
                grid: {
                    bottom: 66,
                    containLabel: true
                },
                xAxis: {
                    type: 'category',
                    splitLine: {show:false},
                    data: Statsdata.xdata
                },
                yAxis: {
                    type: 'value',
                    axisLabel: {
                        formatter:'{value}%'
                    }
                },
                dataZoom: [{
                    type: 'inside'
                }, {
                    type: 'slider'
                }],
                series: [{
                    data: Statsdata.ydata,
                    type: 'bar',
                    label: {
                        normal: {
                            show: true,
                            position: 'inside'
                        }
                    },
                }]
            };

            myChart.setOption(option);

        },
        ygyg2: function () {

            var myChart = Echarts.init(document.getElementById('echart'), 'walden');

            option = {
                tooltip : {
                    trigger: 'axis',
                    axisPointer : {            // 坐標軸指示器，坐標軸觸發有效
                        type : 'shadow'        // 默認為直線，可選為：'line' | 'shadow'
                    },
                },
                title: {
                    text: '每日用工預估',
                    subtext: '投入人力:' + Statsdata.mannum + '人', //小灰字
                    left: 'center'
                },
                grid: {
                    bottom: 66,
                    containLabel: true
                },
                xAxis: {
                    type: 'category',
                    splitLine: {show:false},
                    data: Statsdata.xdata
                },
                yAxis: {
                    type: 'value',
                    axisLabel: {
                        formatter:'{value}%'
                    }
                },
                dataZoom: [{
                    type: 'inside'
                }, {
                    type: 'slider'
                }],
                series: [{
                    data: Statsdata.ydata,
                    type: 'bar',
                    label: {
                        normal: {
                            show: true,
                            position: 'inside'
                        }
                    },
                }]
            };

            myChart.setOption(option);

        },
        add: function () {

            $(document).on("click", "#b-subprocess", function () {
                var url = 'aps/planlog/subprocess';
                var options = {
                    shadeClose: false,
                    shade: [0.3, '#393D49'],
                    area: ["100%", "100%"],
                    callback:function(data){
                        //$("#c-idnumber").val(data.idnumber);

                        $("#c-subprocess_id").val(data.id);
                        $("#c-subprocess").val(data.subname);

                        $("#c-mainprocess_id").val(data.mainprocess_id);
                        $("#c-mainprocess").val(data.mainprocess_name);

                        updateprocedure(data);
                        changehours();

                    }
                };
                Fast.api.open(url, "歷史子制程列表", options);
            });

            $(document).on("click", "#b-mainprocess", function () {
                var url = 'aps/planlog/mainprocess';
                var options = {
                    shadeClose: false,
                    shade: [0.3, '#393D49'],
                    area: ["100%", "100%"],
                    callback:function(data){
                        console.log(data);

                        //$("#c-subprocess_id").val(0);
                        //$("#c-subprocess").val('');

                        $("#c-mainprocess_id").val(data.id);
                        $("#c-mainprocess").val(data.name);

                        updateprocedure(data);
                        changehours();
                    }
                };
                Fast.api.open(url, "主制程列表", options);
            });

            function updateprocedure(data) {
                $("#c-procedure1_id").val(data.procedure1_id);
                $("#c-procedure1").val(data.procedure1_name);
                $("#c-procedure1_manhours_s").val(data.procedure1_manhours);
                $("#c-procedure2_id").val(data.procedure2_id);
                $("#c-procedure2").val(data.procedure2_name);
                $("#c-procedure2_manhours_s").val(data.procedure2_manhours);
                $("#c-procedure3_id").val(data.procedure3_id);
                $("#c-procedure3").val(data.procedure3_name);
                $("#c-procedure3_manhours_s").val(data.procedure3_manhours);
                $("#c-procedure4_id").val(data.procedure4_id);
                $("#c-procedure4").val(data.procedure4_name);
                $("#c-procedure4_manhours_s").val(data.procedure4_manhours);
                $("#c-procedure5_id").val(data.procedure5_id);
                $("#c-procedure5").val(data.procedure5_name);
                $("#c-procedure5_manhours_s").val(data.procedure5_manhours);
                $("#c-procedure6_id").val(data.procedure6_id);
                $("#c-procedure6").val(data.procedure6_name);
                $("#c-procedure6_manhours_s").val(data.procedure6_manhours);
                $("#c-procedure7_id").val(data.procedure7_id);
                $("#c-procedure7").val(data.procedure7_name);
                $("#c-procedure7_manhours_s").val(data.procedure7_manhours);
                $("#c-procedure8_id").val(data.procedure8_id);
                $("#c-procedure8").val(data.procedure8_name);
                $("#c-procedure8_manhours_s").val(data.procedure8_manhours);
                $("#c-procedure9_id").val(data.procedure9_id);
                $("#c-procedure9").val(data.procedure9_name);
                $("#c-procedure9_manhours_s").val(data.procedure9_manhours);
                $("#c-procedure10_id").val(data.procedure10_id);
                $("#c-procedure10").val(data.procedure10_name);
                $("#c-procedure10_manhours_s").val(data.procedure10_manhours);
                $("#c-procedure11_id").val(data.procedure11_id);
                $("#c-procedure11").val(data.procedure11_name);
                $("#c-procedure11_manhours_s").val(data.procedure11_manhours);
                $("#c-procedure12_id").val(data.procedure12_id);
                $("#c-procedure12").val(data.procedure12_name);
                $("#c-procedure12_manhours_s").val(data.procedure12_manhours);
            }

            function changehours() {
                var num = $("#c-num").val();
                $procedure1_manhours = $("#c-procedure1_manhours_s").val();
                $("#c-procedure1_manhours").val(Controller.api.Trans0($procedure1_manhours * num));
                $procedure2_manhours = $("#c-procedure2_manhours_s").val();
                $("#c-procedure2_manhours").val(Controller.api.Trans0($procedure2_manhours * num));
                $procedure3_manhours = $("#c-procedure3_manhours_s").val();
                $("#c-procedure3_manhours").val(Controller.api.Trans0($procedure3_manhours * num));
                $procedure4_manhours = $("#c-procedure4_manhours_s").val();
                $("#c-procedure4_manhours").val(Controller.api.Trans0($procedure4_manhours * num));
                $procedure5_manhours = $("#c-procedure5_manhours_s").val();
                $("#c-procedure5_manhours").val(Controller.api.Trans0($procedure5_manhours * num));
                $procedure6_manhours = $("#c-procedure6_manhours_s").val();
                $("#c-procedure6_manhours").val(Controller.api.Trans0($procedure6_manhours * num));
                $procedure7_manhours = $("#c-procedure7_manhours_s").val();
                $("#c-procedure7_manhours").val(Controller.api.Trans0($procedure7_manhours * num));
                $procedure8_manhours = $("#c-procedure8_manhours_s").val();
                $("#c-procedure8_manhours").val(Controller.api.Trans0($procedure8_manhours * num));
                $procedure9_manhours = $("#c-procedure9_manhours_s").val();
                $("#c-procedure9_manhours").val(Controller.api.Trans0($procedure9_manhours * num));
                $procedure10_manhours = $("#c-procedure10_manhours_s").val();
                $("#c-procedure10_manhours").val(Controller.api.Trans0($procedure10_manhours * num));
                $procedure11_manhours = $("#c-procedure11_manhours_s").val();
                $("#c-procedure11_manhours").val(Controller.api.Trans0($procedure11_manhours * num));
                $procedure12_manhours = $("#c-procedure12_manhours_s").val();
                $("#c-procedure12_manhours").val(Controller.api.Trans0($procedure12_manhours * num));
            }

            $(document).on("change", "#c-num", function () {
                changehours();
            });


            $(document).on("click", "#b-procedure1", function () {
                $("#c-procedure1_id").val(0);
                $("#c-procedure1").val('');
                $("#c-procedure1_manhours").val('');
            });
            $(document).on("click", "#b-procedure2", function () {
                $("#c-procedure2_id").val(0);
                $("#c-procedure2").val('');
                $("#c-procedure2_manhours").val('');
            });
            $(document).on("click", "#b-procedure3", function () {
                $("#c-procedure3_id").val(0);
                $("#c-procedure3").val('');
                $("#c-procedure3_manhours").val('');
            });
            $(document).on("click", "#b-procedure4", function () {
                $("#c-procedure4_id").val(0);
                $("#c-procedure4").val('');
                $("#c-procedure4_manhours").val('');
            });
            $(document).on("click", "#b-procedure5", function () {
                $("#c-procedure5_id").val(0);
                $("#c-procedure5").val('');
                $("#c-procedure5_manhours").val('');
            });
            $(document).on("click", "#b-procedure6", function () {
                $("#c-procedure6_id").val(0);
                $("#c-procedure6").val('');
                $("#c-procedure6_manhours").val('');
            });
            $(document).on("click", "#b-procedure7", function () {
                $("#c-procedure7_id").val(0);
                $("#c-procedure7").val('');
                $("#c-procedure7_manhours").val('');
            });
            $(document).on("click", "#b-procedure8", function () {
                $("#c-procedure8_id").val(0);
                $("#c-procedure8").val('');
                $("#c-procedure8_manhours").val('');
            });
            $(document).on("click", "#b-procedure9", function () {
                $("#c-procedure9_id").val(0);
                $("#c-procedure9").val('');
                $("#c-procedure9_manhours").val('');
            });
            $(document).on("click", "#b-procedure10", function () {
                $("#c-procedure10_id").val(0);
                $("#c-procedure10").val('');
                $("#c-procedure10_manhours").val('');
            });
            $(document).on("click", "#b-procedure11", function () {
                $("#c-procedure11_id").val(0);
                $("#c-procedure11").val('');
                $("#c-procedure11_manhours").val('');
            });
            $(document).on("click", "#b-procedure12", function () {
                $("#c-procedure12_id").val(0);
                $("#c-procedure12").val('');
                $("#c-procedure12_manhours").val('');
            });
            Controller.api.bindevent();
        },
        edit: function () {
            $(document).on("click", ".btn-proclear[data-id]", function () {
                var finisnum = $(this).data('id');
                Controller.api.clearprocedure(finisnum);
            });

            Controller.api.bindevent();
        },
        detail: function () {
            // 初始化表格參數配置
            Table.api.init({
                extend: {
                    index_url: 'aps/planlog/detail?ids=' + Config.ids,
                    add_url: '',
                    edit_url: 'aps/planlog/edit2',
                    del_url: '',
                    multi_url: '',
                    table: 'aps_planlog',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showColumns: false,
                //commonSearch: false,
                showExport: false,
                pageSize: 'All',
                pageList: ['All'],
                columns: [
                    [
                        {field: 'id', title: __('順序'), operate:false},
                        {field: 'procedure_name', title: __('工序名稱'), operate:false},
                        {field: 'procedure_man_name', title: __('工作人員'), operate:false},
                        {field: 'procedure_mannum', title: __('目前人力'), operate:false},
                        {
                            field: 'procedure_mannum2',
                            title: __('調整人力'),
                            editable: {
                                emptytext: '無',
                                rows:10,
                                tpl: "<textarea rows='10' cols='50'></textarea>",
                                success: function (response, newValue) {
                                    //$(".btn-refresh").trigger("click");
                                }
                            },
                            operate: false,
                            align: 'left',
                        },
                        //{field: 'procedure_preparedate', title: __('工序原料備齊日*'), editable: true, operate:false},
                        {field: 'procedure_startdate', title: __('工序開工日'), operate:false, formatter: Controller.api.formatter.datet},
                        {field: 'procedure_finishdate', title: __('工序完工日'), operate:false, formatter: Controller.api.formatter.datet},
                        {field: 'procedure_manhours', title: __('工序工時'), operate:false},
                        {field: 'finish', title: __('是否完工'), operate:false},
                    ]
                ]
            });

            // 為表格綁定事件
            Table.api.bindevent(table);

            Controller.detail_forworkorder();

            Controller.gantt_z();
        },
        detail_forworkorder: function () {

            var table = $("#table1");

            // 初始化表格
            table.bootstrapTable({
                url: 'aps/planlog/detail_forworkorder?ids=' + Config.ids,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showColumns: false,
                commonSearch: false,
                showExport: false,
                paginationDetailHAlign:' hidden', //不顯示分頁信息
                columns: [
                    [
                        {field: 'name', title: __('Name'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符'},
                        {field: 'MainProcessName', title: __('規格'), operate:false},
                        {field: 'ProductNumber', title: __('產品品號'), operate:false},
                        {field: 'ProductName', title: __('產品品名'), operate:false},
                        {field: 'num', title: __('數量')}
                    ]
                ]
            });

            // 為表格綁定事件
            Table.api.bindevent(table);
        },
        mainprocess: function () {
            // 初始化表格參數配置
            Table.api.init({
                extend: {
                    index_url: 'aps/planlog/mainprocess',
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: '',
                    table: 'aps_planlog',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showColumns: false,
                searchFormVisible: true,
                showExport: false,
                columns: [
                    [
                        {
                            field: 'buttons',
                            width: "60px",
                            title: __('操作'),
                            table: table,
                            events: Table.api.events.operate,
                            operate:false,
                            buttons: [
                                {
                                    name: '加入',
                                    text: __('加入'),
                                    title: __('加入選中主制程'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-magic',
                                    url: 'aps/planlog/addmainprocess',
                                    success: function (data, ret) {
                                        //Layer.alert(ret.msg + ",返回數據：" + JSON.stringify(data));
                                        //如果需要阻止成功提示，則必須使用return false;
                                        Fast.api.close(data);
                                        return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                        {field: 'id', title: __('Id'), operate:false},
                        {field: 'name', title: __('主制程名'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符'},
                        {field: 'manhours', title: __('主制程總工時'), operate:false},
                        {field: 'procedure1_name', title: __('工序1名'), operate:false},
                        {field: 'procedure1_manhours', title: __('工序1工時'), operate:false},
                        {field: 'procedure2_name', title: __('工序2名'), operate:false},
                        {field: 'procedure2_manhours', title: __('工序2工時'), operate:false},
                        {field: 'procedure3_name', title: __('工序3名'), operate:false},
                        {field: 'procedure3_manhours', title: __('工序3工時'), operate:false},
                        {field: 'procedure4_name', title: __('工序4名'), operate:false},
                        {field: 'procedure4_manhours', title: __('工序4工時'), operate:false},
                        {field: 'procedure5_name', title: __('工序5名'), operate:false},
                        {field: 'procedure5_manhours', title: __('工序5工時'), operate:false},
                        {field: 'procedure6_name', title: __('工序6名'), operate:false},
                        {field: 'procedure6_manhours', title: __('工序6工時'), operate:false},
                        {field: 'procedure7_name', title: __('工序7名'), operate:false},
                        {field: 'procedure7_manhours', title: __('工序7工時'), operate:false},
                        {field: 'procedure8_name', title: __('工序8名'), operate:false},
                        {field: 'procedure8_manhours', title: __('工序8工時'), operate:false},
                    ]
                ]
            });


            // 為表格綁定事件
            Table.api.bindevent(table);

        },
        subprocess: function () {
            // 初始化表格參數配置
            Table.api.init({
                extend: {
                    index_url: 'aps/planlog/subprocess',
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: '',
                    table: 'aps_planlog',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showColumns: false,
                searchFormVisible: true,
                showExport: false,
                columns: [
                    [
                        {
                            field: 'buttons',
                            operate:false,
                            width: "60px",
                            title: __('操作'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: '加入',
                                    text: __('加入'),
                                    title: __('加入選中子制程'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-magic',
                                    url: 'aps/planlog/addsubprocess',
                                    success: function (data, ret) {
                                        //Layer.alert(ret.msg + ",返回數據：" + JSON.stringify(data));
                                        //如果需要阻止成功提示，則必須使用return false;
                                        console.log(data, ret);
                                        Fast.api.close(data);
                                        return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        },

                        {field: 'id', title: __('Id'), operate:false},
                        {field: 'subname', title: __('子制程名'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符'},
                        {field: 'mainprocess.name', title: __('主制程名'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符'},
                        {field: 'mainprocess.manhours', title: __('主制程總工時'), operate:false},
                        {field: 'procedure1_name', title: __('工序1名'), operate:false},
                        {field: 'procedure1_manhours', title: __('工序1工時'), operate:false},
                        {field: 'procedure1_name', title: __('工序2名'), operate:false},
                        {field: 'procedure2_manhours', title: __('工序1工時'), operate:false},
                        {field: 'procedure1_name', title: __('工序3名'), operate:false},
                        {field: 'procedure3_manhours', title: __('工序1工時'), operate:false},
                        {field: 'procedure1_name', title: __('工序4名'), operate:false},
                        {field: 'procedure4_manhours', title: __('工序1工時'), operate:false},
                        {field: 'procedure1_name', title: __('工序5名'), operate:false},
                        {field: 'procedure5_manhours', title: __('工序1工時'), operate:false},
                        {field: 'procedure1_name', title: __('工序6名'), operate:false},
                        {field: 'procedure6_manhours', title: __('工序1工時'), operate:false},
                        {field: 'procedure1_name', title: __('工序7名'), operate:false},
                        {field: 'procedure7_manhours', title: __('工序1工時'), operate:false},
                        {field: 'procedure1_name', title: __('工序8名'), operate:false},
                        {field: 'procedure8_manhours', title: __('工序1工時'), operate:false},
                        {field: 'procedure1_name', title: __('工序9名'), operate:false},
                        {field: 'procedure9_manhours', title: __('工序1工時'), operate:false},
                        {field: 'procedure1_name', title: __('工序10名'), operate:false},
                        {field: 'procedure10_manhours', title: __('工序1工時'), operate:false},
                        {field: 'procedure1_name', title: __('工序11名'), operate:false},
                        {field: 'procedure11_manhours', title: __('工序1工時'), operate:false},
                        {field: 'procedure1_name', title: __('工序12名'), operate:false},
                        {field: 'procedure12_manhours', title: __('工序1工時'), operate:false},
                    ]
                ]
            });

            // 為表格綁定事件
            Table.api.bindevent(table);

        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            defaultdate: function () {
                var date = new Date();
                var year = date.getFullYear();
                var month = date.getMonth() + 1;//獲取當前月份(0-11,0代表1月)
                if (month >= 10) {
                    month = "" + month;
                } else {
                    month = "0" + month;
                }
                var day = date.getDate();
                if (day >= 10) {
                    day = "" + day;
                } else {
                    day = "0" + day;
                }
                //console.log("QQQ---" + year + "-" + month);
                return year + "-" + month + "-" + day;
            },
            clearprocedure: function (finisnum) {
                $("#c-finishnum").val(finisnum);
                if (finisnum == 0) {
                    $("#c-procedure1_startdate").val('');
                    $("#c-procedure1_finishdate").val('');
                    $("#c-procedure2_startdate").val('');
                    $("#c-procedure2_finishdate").val('');
                    $("#c-procedure3_startdate").val('');
                    $("#c-procedure3_finishdate").val('');
                    $("#c-procedure4_startdate").val('');
                    $("#c-procedure4_finishdate").val('');
                    $("#c-procedure5_startdate").val('');
                    $("#c-procedure5_finishdate").val('');
                    $("#c-procedure6_startdate").val('');
                    $("#c-procedure6_finishdate").val('');
                    $("#c-procedure7_startdate").val('');
                    $("#c-procedure7_finishdate").val('');
                    $("#c-procedure8_startdate").val('');
                    $("#c-procedure8_finishdate").val('');
                    $("#c-procedure9_startdate").val('');
                    $("#c-procedure9_finishdate").val('');
                    $("#c-procedure10_startdate").val('');
                    $("#c-procedure10_finishdate").val('');
                    $("#c-procedure11_startdate").val('');
                    $("#c-procedure11_finishdate").val('');
                    $("#c-procedure12_startdate").val('');
                    $("#c-procedure12_finishdate").val('');
                } else if (finisnum == 1) {
                    $("#c-procedure2_startdate").val('');
                    $("#c-procedure2_finishdate").val('');
                    $("#c-procedure3_startdate").val('');
                    $("#c-procedure3_finishdate").val('');
                    $("#c-procedure4_startdate").val('');
                    $("#c-procedure4_finishdate").val('');
                    $("#c-procedure5_startdate").val('');
                    $("#c-procedure5_finishdate").val('');
                    $("#c-procedure6_startdate").val('');
                    $("#c-procedure6_finishdate").val('');
                    $("#c-procedure7_startdate").val('');
                    $("#c-procedure7_finishdate").val('');
                    $("#c-procedure8_startdate").val('');
                    $("#c-procedure8_finishdate").val('');
                    $("#c-procedure9_startdate").val('');
                    $("#c-procedure9_finishdate").val('');
                    $("#c-procedure10_startdate").val('');
                    $("#c-procedure10_finishdate").val('');
                    $("#c-procedure11_startdate").val('');
                    $("#c-procedure11_finishdate").val('');
                    $("#c-procedure12_startdate").val('');
                    $("#c-procedure12_finishdate").val('');
                } else if (finisnum == 2) {
                    $("#c-procedure3_startdate").val('');
                    $("#c-procedure3_finishdate").val('');
                    $("#c-procedure4_startdate").val('');
                    $("#c-procedure4_finishdate").val('');
                    $("#c-procedure5_startdate").val('');
                    $("#c-procedure5_finishdate").val('');
                    $("#c-procedure6_startdate").val('');
                    $("#c-procedure6_finishdate").val('');
                    $("#c-procedure7_startdate").val('');
                    $("#c-procedure7_finishdate").val('');
                    $("#c-procedure8_startdate").val('');
                    $("#c-procedure8_finishdate").val('');
                    $("#c-procedure9_startdate").val('');
                    $("#c-procedure9_finishdate").val('');
                    $("#c-procedure10_startdate").val('');
                    $("#c-procedure10_finishdate").val('');
                    $("#c-procedure11_startdate").val('');
                    $("#c-procedure11_finishdate").val('');
                    $("#c-procedure12_startdate").val('');
                    $("#c-procedure12_finishdate").val('');
                } else if (finisnum == 3) {
                    $("#c-procedure4_startdate").val('');
                    $("#c-procedure4_finishdate").val('');
                    $("#c-procedure5_startdate").val('');
                    $("#c-procedure5_finishdate").val('');
                    $("#c-procedure6_startdate").val('');
                    $("#c-procedure6_finishdate").val('');
                    $("#c-procedure7_startdate").val('');
                    $("#c-procedure7_finishdate").val('');
                    $("#c-procedure8_startdate").val('');
                    $("#c-procedure8_finishdate").val('');
                    $("#c-procedure9_startdate").val('');
                    $("#c-procedure9_finishdate").val('');
                    $("#c-procedure10_startdate").val('');
                    $("#c-procedure10_finishdate").val('');
                    $("#c-procedure11_startdate").val('');
                    $("#c-procedure11_finishdate").val('');
                    $("#c-procedure12_startdate").val('');
                    $("#c-procedure12_finishdate").val('');
                } else if (finisnum == 4) {
                    $("#c-procedure5_startdate").val('');
                    $("#c-procedure5_finishdate").val('');
                    $("#c-procedure6_startdate").val('');
                    $("#c-procedure6_finishdate").val('');
                    $("#c-procedure7_startdate").val('');
                    $("#c-procedure7_finishdate").val('');
                    $("#c-procedure8_startdate").val('');
                    $("#c-procedure8_finishdate").val('');
                    $("#c-procedure9_startdate").val('');
                    $("#c-procedure9_finishdate").val('');
                    $("#c-procedure10_startdate").val('');
                    $("#c-procedure10_finishdate").val('');
                    $("#c-procedure11_startdate").val('');
                    $("#c-procedure11_finishdate").val('');
                    $("#c-procedure12_startdate").val('');
                    $("#c-procedure12_finishdate").val('');
                } else if (finisnum == 5) {
                    $("#c-procedure6_startdate").val('');
                    $("#c-procedure6_finishdate").val('');
                    $("#c-procedure7_startdate").val('');
                    $("#c-procedure7_finishdate").val('');
                    $("#c-procedure8_startdate").val('');
                    $("#c-procedure8_finishdate").val('');
                    $("#c-procedure9_startdate").val('');
                    $("#c-procedure9_finishdate").val('');
                    $("#c-procedure10_startdate").val('');
                    $("#c-procedure10_finishdate").val('');
                    $("#c-procedure11_startdate").val('');
                    $("#c-procedure11_finishdate").val('');
                    $("#c-procedure12_startdate").val('');
                    $("#c-procedure12_finishdate").val('');
                } else if (finisnum == 6) {
                    $("#c-procedure7_startdate").val('');
                    $("#c-procedure7_finishdate").val('');
                    $("#c-procedure8_startdate").val('');
                    $("#c-procedure8_finishdate").val('');
                    $("#c-procedure9_startdate").val('');
                    $("#c-procedure9_finishdate").val('');
                    $("#c-procedure10_startdate").val('');
                    $("#c-procedure10_finishdate").val('');
                    $("#c-procedure11_startdate").val('');
                    $("#c-procedure11_finishdate").val('');
                    $("#c-procedure12_startdate").val('');
                    $("#c-procedure12_finishdate").val('');
                } else if (finisnum == 7) {
                    $("#c-procedure8_startdate").val('');
                    $("#c-procedure8_finishdate").val('');
                    $("#c-procedure9_startdate").val('');
                    $("#c-procedure9_finishdate").val('');
                    $("#c-procedure10_startdate").val('');
                    $("#c-procedure10_finishdate").val('');
                    $("#c-procedure11_startdate").val('');
                    $("#c-procedure11_finishdate").val('');
                    $("#c-procedure12_startdate").val('');
                    $("#c-procedure12_finishdate").val('');
                } else if (finisnum == 8) {
                    $("#c-procedure9_startdate").val('');
                    $("#c-procedure9_finishdate").val('');
                    $("#c-procedure10_startdate").val('');
                    $("#c-procedure10_finishdate").val('');
                    $("#c-procedure11_startdate").val('');
                    $("#c-procedure11_finishdate").val('');
                    $("#c-procedure12_startdate").val('');
                    $("#c-procedure12_finishdate").val('');
                } else if (finisnum == 9) {
                    $("#c-procedure10_startdate").val('');
                    $("#c-procedure10_finishdate").val('');
                    $("#c-procedure11_startdate").val('');
                    $("#c-procedure11_finishdate").val('');
                    $("#c-procedure12_startdate").val('');
                    $("#c-procedure12_finishdate").val('');
                } else if (finisnum == 10) {
                    $("#c-procedure11_startdate").val('');
                    $("#c-procedure11_finishdate").val('');
                    $("#c-procedure12_startdate").val('');
                    $("#c-procedure12_finishdate").val('');
                } else if (finisnum == 11) {
                    $("#c-procedure12_startdate").val('');
                    $("#c-procedure12_finishdate").val('');
                }

            },
            Trans0: function (d) {
                if (d == 0) {
                    return '';
                }
                return Math.round(d * 10) / 10;
            },
            prdate: function (finishdate, finishnum, plannum) {
                //昨天的時間
                var day1 = new Date();
                day1.setDate(day1.getDate() - 1);
                day1.setHours(0,0,0,0);
                var day2 = new Date(finishdate);
                day2.setHours(0, 0, 0, 0);
                //if (day1.getTime() == day2.getTime()) {
                //    console.log(day1, day2);
                //}

                if (finishdate == '0000-00-00 00:00:00') {
                    finishdate = '';
                }

                if (finishnum == (plannum - 1) && day1.getTime() >= day2.getTime()) {
                    return [
                        '<a href="#" class="text-danger" > ' + finishdate + '</a>'
                    ].join("")
                }  else {
                    return finishdate;
                }
            },
            formatter: {//渲染的方法
                mainprocess: function (value, row, index) {
                    //return [
                    //    '<a href="javascript:;" class="mainprocess" data-id="/admin/aps/procedure/index/ids/' + row.workorder.mainprocess_id + '?&ref=addtabs"  target="_parent" >' + value + '</a>'
                    //].join("")
                    return [
                        '<a class="btn-addtabs" title="管理" href="/admin/aps/procedure/index/ids/' + row.workorder.mainprocess_id + '"  >' + value + '</a>'
                    ].join("")
                },
                manhours2:function (value, row, index) {
                    return [
                        '<a href="javascript:;" class="manhours2"  >' + value + '</a>'
                    ].join("")
                },
                pr1: function (value, row, index) {
                    return Controller.api.prdate(row.procedure1_finishdate, row.finishnum, 1);
                },
                pr2: function (value, row, index) {
                    return Controller.api.prdate(row.procedure2_finishdate, row.finishnum, 2);
                },
                pr3: function (value, row, index) {
                    return Controller.api.prdate(row.procedure3_finishdate, row.finishnum, 3);
                },
                pr4: function (value, row, index) {
                    return Controller.api.prdate(row.procedure4_finishdate, row.finishnum, 4);
                },
                pr5: function (value, row, index) {
                    return Controller.api.prdate(row.procedure5_finishdate, row.finishnum, 5);
                },
                pr6: function (value, row, index) {
                    return Controller.api.prdate(row.procedure6_finishdate, row.finishnum, 6);
                },
                pr7: function (value, row, index) {
                    return Controller.api.prdate(row.procedure7_finishdate, row.finishnum, 7);
                },
                pr8: function (value, row, index) {
                    return Controller.api.prdate(row.procedure8_finishdate, row.finishnum, 8);
                },
                pr9: function (value, row, index) {
                    return Controller.api.prdate(row.procedure9_finishdate, row.finishnum, 9);
                },
                pr10: function (value, row, index) {
                    return Controller.api.prdate(row.procedure10_finishdate, row.finishnum, 10);
                },
                pr11: function (value, row, index) {
                    return Controller.api.prdate(row.procedure11_finishdate, row.finishnum, 11);
                },
                pr12: function (value, row, index) {
                    return Controller.api.prdate(row.procedure12_finishdate, row.finishnum, 12);
                },
                jhwg: function (value, row, index) {

                    var day1 = new Date(value);
                    day1.setHours(0,0,0,0);
                    var day2 = new Date(row.workorder_finishdate);
                    day2.setHours(0,0,0,0);

                    if (day1.getTime() > day2.getTime()) {
                        return [
                            '<a href="#" class="text-danger" > ' + value + '</a>'
                        ].join("")
                    }
                    return value;
                },
                sjwg: function (value, row, index) {
                    var finishdate = '';
                    if (row.maxnum == row.finishnum) {
                        finishdate = row.update_time;
                    }
                    return finishdate;
                },
                datet: function (value, row, index) {
                    if (value == '0000-00-00 00:00:00') {
                        value = '';
                    }
                    return value;
                }
            }
        }
    };
    return Controller;
});

